// mixins/debounceMixin.js
export default {
  data() {
    return {
      debounceTimers: {}
    };
  },
  methods: {
    debounce(func, wait) {
      return function(...args) {
        const context = this;
        const key = func.toString();
        clearTimeout(this.debounceTimers[key]);
        this.debounceTimers[key] = setTimeout(() => func.apply(context, args), wait);
      };
    },
    clearDebounce(func) {
      const key = func.toString();
      clearTimeout(this.debounceTimers[key]);
      delete this.debounceTimers[key];
    }
  },
  beforeDestroy() {
    Object.keys(this.debounceTimers).forEach(key => {
      clearTimeout(this.debounceTimers[key]);
    });
    this.debounceTimers = {};
  }
};